<%--
  Created by IntelliJ IDEA.
  User: liuxuebing
  Date: 2018/10/9
  Time: 20:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/meta.jsp"%>
<html>
<head>
    <title>Title</title>
</head>
<body>
<div class="easyui-layout"  data-options="fit:true" id="deptView">

    <div data-options="region:'north',border:false"
         style="padding: 0px;height: 410px">
        <table id="deptList" class="easyui-datagrid" fit="true" singleSelect="true" fitColumns="true"
               url="${ctx}/dept/list" toolbar="#deptList_toolbar"
               title="部门列表"
               rownumbers="true" pagination="true">
            <thead>
            <tr>
                <th field="departName" width="80">部门名称</th>
            </tr>
            </thead>
        </table>

        <div id="personDialog"></div>
        <div id="deptList_toolbar" tag=listen_hotkey>
            <table class="table_form_result">
                <caption>
                    <a href="javascript:void(0);" class="a_btn_blue" tag="add"><em>新增</em></a>
                    <a href="javascript:void(0);" class="a_btn_green" tag="edit"><em>修改</em></a>
                    <a href="javascript:void(0);" class="a_btn_red" tag="del"><em>删除</em></a>
                </caption>
            </table>
        </div>
    </div>
</div>
<script type="text/javascript">
    $("#deptList").datagrid({
        //双击事件
        onDblClickRow: function (index, row) {
            $("#deptList_toolbar").find("[tag=edit]").click();
        }
    });
    $("#deptList_toolbar").find("[tag=add]").click(function () {
        new openWindows({
            id:'personDialog',
            title: '新增部门',
            width: 400,
            height: 210,
            url: '${ctx}/dept/info'
        });
    });
    $("#deptList_toolbar").find("[tag=edit]").click(function () {
        var row = $("#deptList").datagrid("getSelected");
        if (!row){
            $.messager.alert("提示", "请选择一条记录!", "warning");
            return;
        }
        new openWindows({
            id:'personDialog',
            title: '修改部门',
            width: 400,
            height: 210,
            url: '${ctx}/dept/info?id='+row.id
        });
    });
    $("#deptList_toolbar").find("[tag=del]").click(function () {
        var row = $("#deptList").datagrid("getSelected");
        if (!row){
            $.messager.alert("提示", "请选择一条记录!", "warning");
            return;
        }
        $.messager.confirm('确认', '您确认要删除该条数据？', function (r) {
            if (r) {
                ajaxLoading();
                $.post("${ctx}/dept/delDept",{id:row.id},function (data) {
                    ajaxLoadEnd();
                    if(data.success){
                        $.messager.alert('提示','删除成功');
                        $("#deptList").datagrid('reload');
                    }else {
                        $.messager.alert('提示',data.mes);
                    }
                });
            }
        });
    });
</script>
</body>
</html>
